﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_ReturnManage : System.Web.UI.Page
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        lblPath.Text = f.getModuleidAdd(Request["moduid"]);
        if (!IsPostBack)
        {
            initData();
        }
    }



    private void initData()
    {
        string sql = "select * from (select a.*,(select top 1 realname from UserInfo where a.userid=userid) as realname, (select top 1 GuestName from CS_Guest where a.guestid=guestid) as GuestName,(select top 1 StaffName from CS_Staff where StaffId=a.Saleman) as  StaffName,(select top 1 deptName from department where a.deptid=deptid) as deptName,(select top 1 ReturnId from CS_Return where a.SalesId=SalesId) as ReturnId  from CS_Sales a )TblSales where 1=1  order by SalesId desc";

        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;


    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

        string sql = "select * from (select a.*,(select top 1 realname from UserInfo where a.userid=userid) as realname, (select top 1 GuestName from CS_Guest where a.guestid=guestid) as GuestName,(select top 1 StaffName from CS_Staff where StaffId=a.Saleman) as  StaffName,(select top 1 deptName from department where a.deptid=deptid) as deptName,(select top 1 ReturnId from CS_Return where a.SalesId=SalesId) as ReturnId  from CS_Sales a )TblSales where 1=1 ";

        if (!string.IsNullOrEmpty(txtSalesCode.Text))//订单号
        {
            sql += " and SalesCode='" + Common.FormatParameter(txtSalesCode.Text).Trim() + "'";
        }
        if (!string.IsNullOrEmpty(txtGuest.Text))//客户名称
        {
            sql += " and GuestName like '%" + Common.FormatParameter(txtGuest.Text).Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(txtComodName.Text))
        {
            sql += " and comodName like '%" + Common.FormatParameter(txtComodName.Text).Trim() + "%' ";
        }

        if (!string.IsNullOrEmpty(txtModul.Text))//型号
        {
            sql += " and modul like'%" + Common.FormatParameter(txtModul.Text).Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(txtKdate.Text) && !string.IsNullOrEmpty(txtJdate.Text.Trim()))//时间起止
        {
            sql += " and C_date >='" + Common.FormatParameter(txtKdate.Text) + " 00:00:00' and C_date<='" + Common.FormatParameter(txtJdate.Text) + " 23:59:59'";
        }

        if (!string.IsNullOrEmpty(ddltypeSale.SelectedValue))//销售类型
        {
            sql += " and typeSale =" + Common.FormatParameter(ddltypeSale.SelectedValue.Trim());
        }

        if (!string.IsNullOrEmpty(ddrIsDel.SelectedValue))//作废
        {
            sql += " and IsDel =" + Common.FormatParameter(ddrIsDel.SelectedValue.Trim());
        }

        //if (HidWareid.Value != "0")
        //{

        //    sql += " and warehouse=" + HidWareid.Value;
        //}
        sql += " order by SalesId desc";
        //lblPath.Text = sql;
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }


    protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)//在邦定数据
    {
        //f.checkLevels(Request.Cookies["user"].Values["roleid"], hfxs.Value, 4, GvDataType, btndel, btnallflag, btnAdd);//权限
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int typeSale = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "typeSale"));
            if (typeSale == 1)
                e.Row.Cells[12].Text = "零售";
            else if (typeSale == 2)
                e.Row.Cells[12].Text = "批发";
            else if (typeSale == 3)
                e.Row.Cells[12].Text = "工程";
            else
                e.Row.Cells[12].Text = "未知";

            int isDel = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "isDel"));//是否发废
            if (isDel == 1)
            {
                e.Row.Cells[16].Text = "发废";
                e.Row.Cells[16].CssClass = "F_red";
            }
            else
            {
                e.Row.Cells[16].Text = "正常";
            }
        }
    }


}
